import request from "@/utils/request"

const JOB_BASE_URL = "/api/object/com.siline.chimes/ChimesJob"

class JobAPI {
  /** 获取岗位分页数据 */
  static getPage(data: QueryCondition = {}) {
    return request<any, ResponseData<PageResult<JobVO[]>>>({
      url: `${JOB_BASE_URL}/paged_query`,
      method: "post",
      data,
    })
  }

  /** 获取岗位下拉数据源 */
  static getOptions(data: QueryCondition = {}) {
    return request<any, ResponseData<OptionType[]>>({
      url: `${JOB_BASE_URL}/query`,
      method: "post",
      data,
    })
  }

  /** 获取岗位数据列表 */
  static query(data: QueryCondition = {}) {
    return request<any, ResponseData<JobVO[]>>({
      url: `${JOB_BASE_URL}/query`,
      method: "post",
      data,
    })
  }

  /**
   * 获取岗位表单数据
   *
   * @param id 岗位ID
   * @returns 岗位表单数据
   */
  static getFormData(id: number) {
    return request<any, ResponseData<JobForm>>({
      url: `${JOB_BASE_URL}/select/${id}`,
      method: "get",
    })
  }

  /** 添加岗位 */
  static add(data: JobForm) {
    return request<any, ResponseData<JobForm>>({
      url: `${JOB_BASE_URL}/insert`,
      method: "post",
      data: data,
    })
  }

  /**
   * 更新岗位
   *
   * @param data 岗位表单数据
   */
  static update(data: JobForm) {
    return request<any, ResponseData<JobForm>>({
      url: `${JOB_BASE_URL}/update`,
      method: "post",
      data: data,
    })
  }

  /**
   * 根据条件批量删除岗位
   *
   * @param data
   */
  static deleteByCondition(data: QueryCondition) {
    return request({
      url: `${JOB_BASE_URL}/delete_by`,
      method: "post",
      data: data,
    })
  }
}
export default JobAPI

/** 岗位分页对象 */
export interface JobVO {
  create_by?: number
  create_time?: Date
  enabled?: number
  job_id?: number
  job_sort?: number
  name?: string
  update_by?: number
  update_time?: Date
}

/** 岗位表单对象 */
export interface JobForm {
  enabled?: boolean
  job_id?: number
  job_sort?: number
  name?: string
}
